﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		CategoryUrlBuilder.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System;
using Dexter.CallContext;
using Dexter.DataTransferObject;
using Dexter.Domain.Model;
using Dexter.Logger.Contracts;

namespace Dexter.Services.Implementation {
	/// <summary>
	/// 	The implementation of <see cref = "ICategoryUrlBuilder" />.
	/// </summary>
	public class CategoryUrlBuilder : UrlBuilderBase , ICategoryUrlBuilder {
		/// <summary>
		/// 	Initializes a new instance of the <see cref = "CategoryUrlBuilder" /> class.
		/// </summary>
		/// <param name = "logger">The logger.</param>
		/// <param name = "context">The HTTP context.</param>
		/// <param name = "configurationService">The configuration service.</param>
		public CategoryUrlBuilder ( ILogger logger , IDexterContext context , IConfigurationService configurationService ) : base ( logger , context , configurationService ) {}

		/// <summary>
		/// 	Return the detail url of the specified <see cref = "Category" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Categories/Archive/My-Category/
		/// </example>
		public virtual string Detail ( Category item ) {
			string dt = string.Format ( "Category/Archive/{0}/" , item.Name );
			return ToCaseConfiguration ( new Uri ( HomePage , dt ) );
		}

		/// <summary>
		/// Return the detail url of the specified <see cref="Category"/>.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Categories/Archive/My-Category/
		/// </example>
		public string Detail ( CategoryDto item ) {
			string dt = string.Format ( "Category/Archive/{0}/", item.Name );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// 	Return the feed url of the specified <see cref = "Category" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Categories/Feeds/My-Category/
		/// </example>
		public virtual string Feed ( Category item ) {
			if(item.FeedBurnerUrl != null)
				return item.FeedBurnerUrl.ToString ( );

			string dt = string.Format ( "Category/Feeds/{0}/", item.Name );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// Return the feed url of the specified <see cref="Category"/>.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/blog/fees/2009/05/19/My-Post/
		/// </example>
		public string Feed ( CategoryDto item ) {
			if (item.FeedBurnerUrl != null)
				return item.FeedBurnerUrl.ToString ( );

			string dt = string.Format ( "Category/Feeds/{0}/", item.Name );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// 	Return the edit url of the specified <see cref = "Post" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Admin/Category/Editor/10/
		/// </example>
		public string Edit ( Category item ) {
			string dt = string.Format ( "Admin/Category/Editor/{0}/", item.Id );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// 	Return the edit url of the specified <see cref = "Post" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Admin/Category/Editor/10/
		/// </example>
		public string Edit ( CategoryDto item ) {
			string dt = string.Format ( "Admin/Category/Editor/{0}/", item.Id );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// 	Return the edit url of the specified <see cref = "Post" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Admin/Category/Editor/10/
		/// </example>
		public string Delete ( Category item ) {
			string dt = string.Format ( "Admin/Category/ConfirmDelete/{0}/", item.Id );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}

		/// <summary>
		/// 	Return the edit url of the specified <see cref = "Post" />.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <example>
		/// 	http://dexterblogengine.com/Admin/Category/Editor/10/
		/// </example>
		public string Delete ( CategoryDto item ) {
			string dt = string.Format ( "Admin/Category/ConfirmDelete/{0}/", item.Id );
			return ToCaseConfiguration ( new Uri ( HomePage, dt ) );
		}
	}
}
